package com.tsingtree.modular.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tsingtree.modular.entity.NanSellAnnounceAdvert;
import com.tsingtree.modular.mapper.NanSellAnnounceAdvertMapper;
import com.tsingtree.modular.model.params.NanSellAnnounceAdvertParam;
import com.tsingtree.modular.service.NanSellAnnounceAdvertService;
import com.tsingtree.roses.core.util.ToolUtil;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 社区帖子广告 服务实现类
 * </p>
 *
 * @author jagger
 * @since 2025-10-17
 */
@Service
public class NanSellAnnounceAdvertServiceImpl extends ServiceImpl<NanSellAnnounceAdvertMapper, NanSellAnnounceAdvert> implements NanSellAnnounceAdvertService {

    @Override
    public List<NanSellAnnounceAdvert> findBySellAnnounceId(Integer sellAnnounceId) {
        return this.baseMapper.findBySellAnnounceId(sellAnnounceId);
    }

    @Override
    public void add(NanSellAnnounceAdvertParam param) {
        NanSellAnnounceAdvert entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(NanSellAnnounceAdvertParam param) {
        // 软删除
        NanSellAnnounceAdvert entity = this.getById(getKey(param));
        if (entity != null) {
            entity.setIsDel(true);
            this.updateById(entity);
        }
    }

    @Override
    public NanSellAnnounceAdvert findById(NanSellAnnounceAdvertParam param) {
        return this.getById(getKey(param));
    }

    private Serializable getKey(NanSellAnnounceAdvertParam param) {
        return param.getId();
    }

    private NanSellAnnounceAdvert getEntity(NanSellAnnounceAdvertParam param) {
        NanSellAnnounceAdvert entity = new NanSellAnnounceAdvert();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
